﻿using System;
using System.Collections.Generic; 
using System.Text;
using ATSIDAL;
using ATSModel;
using System.Data.SqlClient;
using System.Data;

namespace ATSDAL
{
    public class TPackConfigDal : BaseRepository_DT<TPackConfigInfo>, ITPackConfig
    {
        #region 静态变量部分
        private const string PACK_ID = "@ID";
        private const string PACK_TPCKCONFIG_PID = "@ProductTypeID";
        private const string PACK_TPCKCONFIG_RSN = "@RSN";
        private const string PACK_TPCKCONFIG_PSN = "@PSN";
        private const string PACK_TPCKCONFIG_OBSN = "@OBSN";
        private const string PACK_TPCKCONFIG_OCSN = "@OCSN";
        private const string PACK_TPCKCONFIG_TBC = "@TBC";
        private const string PACK_TPCKCONFIG_BTBC = "@BTBC";
        private const string PACK_TPCKCONFIG_OCSN1 = "@OCSN1";
        private const string PACK_TPCKCONFIG_OCSN2 = "@OCSN2";
        private const string PACK_TPCKCONFIG_OCSN3 = "@OCSN3";
        private const string PACK_TPCKCONFIG_ALDSN = "@ALDSN";
        private const string PACK_TPCKCONFIG_PCODERULE = "@PCODERULE"; 
        private const string PACK_TPCKCONFIG_PCodeRuleRemark = "@PCodeRuleRemark";
        #endregion

        #region 数据检索部分

        /// <summary>
        /// 检索全部配置信息
        /// </summary>
        /// <returns></returns>
        public IList<TPackConfigInfo> LoadEntities()
        {
            return ExcuteSqlToGetEntities("sp_selTPackConfig");
        }

        /// <summary>
        /// 根据S代码 检索配置信息
        /// </summary>
        /// <param name="productTypeID"></param>
        /// <returns></returns>
        public IList<TPackConfigInfo> TPackConfig_GetbyPID(string productTypeID)
        {
            SqlParameter parm = new SqlParameter(PACK_TPCKCONFIG_PID, SqlDbType.NVarChar, 50);
            parm.Value = productTypeID;
            return ExcuteSqlToGetEntities("sp_selTPackConfigbyProID", parm);
        }

        /// <summary>
        /// 根据S代码 检索配置信息
        /// </summary>
        /// <param name="productTypeID"></param>
        /// <returns></returns>
        public TPackConfigInfo TPConfig_GetbyPID(string productTypeID)
        {
            SqlParameter parm = new SqlParameter(PACK_TPCKCONFIG_PID, SqlDbType.NVarChar, 50);
            parm.Value = productTypeID;
            return ExcuteSqlToGetEntity("sp_selTPackConfigbyProID", parm);
        }



        /// <summary>
        /// 根据ID 获取配置信息
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <param name="id"></param>
        /// <returns></returns>
        public TPackConfigInfo LoadEntity<T1>(T1 id)
        {
            SqlParameter parm = GetParameter();
            parm.Value = id;
            return ExcuteSqlToGetEntity("sp_selTPackConfigbyID", parm);
        } 
        
        #endregion

        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override TPackConfigInfo GetEntityRecord(SqlDataReader rdr)
        {
            TPackConfigInfo pco = new TPackConfigInfo
            {
                ID = rdr.GetInt32(0),
                ProductTypeID = rdr.GetValue(1).ToString(),
                RSN =rdr.GetBoolean(2),
                PSN = rdr.GetBoolean(3),
                OBSN = rdr.GetBoolean(4),
                OCSN = rdr.GetBoolean(5),
                TBC = rdr.GetBoolean(6),
                BTBC = rdr.GetBoolean(7),
                OCSN1 = rdr.GetBoolean(8),
                OCSN2 = rdr.GetBoolean(9),
                OCSN3 = rdr.GetBoolean(10),
                ALDSN = rdr.GetBoolean(11),
                PCodeRule = rdr.GetInt32(12),
                PCodeRuleRemark=rdr.GetValue(13).ToString()
            };
            return pco;
        }

        public override TPackConfigInfo GetEntityRecord()
        {
            TPackConfigInfo pco = new TPackConfigInfo();
            return pco;
        }

        public override string GetInsertsp()
        {
            return "sp_InsertTPackConfig";
        }

        public override string GetUpdatesp()
        {
            return "sp_UpdateTPackConfig";
        }

        public override string GetDeletesp()
        {
            return "sp_DeleteTPackConfig";
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PACK_ID, SqlDbType.Int, 4);
            return Parm;
        }
 

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    //new SqlParameter(PACK_ID, SqlDbType.Int, 4),
					new SqlParameter(PACK_TPCKCONFIG_PID, SqlDbType.NVarChar, 50),
					new SqlParameter(PACK_TPCKCONFIG_RSN, SqlDbType.Bit),
					new SqlParameter(PACK_TPCKCONFIG_PSN, SqlDbType.Bit),
					new SqlParameter(PACK_TPCKCONFIG_OBSN, SqlDbType.Bit),
					new SqlParameter(PACK_TPCKCONFIG_OCSN, SqlDbType.Bit),
					new SqlParameter(PACK_TPCKCONFIG_TBC, SqlDbType.Bit),
					new SqlParameter(PACK_TPCKCONFIG_BTBC, SqlDbType.Bit),
					new SqlParameter(PACK_TPCKCONFIG_OCSN1, SqlDbType.Bit),
					new SqlParameter(PACK_TPCKCONFIG_OCSN2, SqlDbType.Bit),
					new SqlParameter(PACK_TPCKCONFIG_OCSN3, SqlDbType.Bit),
                    new SqlParameter(PACK_TPCKCONFIG_ALDSN, SqlDbType.Bit),
                    new SqlParameter(PACK_TPCKCONFIG_PCODERULE, SqlDbType.Int) 
                };
            return parms;
        }

        public override void SetParameters(TPackConfigInfo tPackConfig, params SqlParameter[] Parms)
        {
            //Parms[0].Value = tPackConfig.ID;
            Parms[0].Value = tPackConfig.ProductTypeID;
            Parms[1].Value = tPackConfig.RSN;
            Parms[2].Value = tPackConfig.PSN;
            Parms[3].Value = tPackConfig.OBSN;
            Parms[4].Value = tPackConfig.OCSN;
            Parms[5].Value = tPackConfig.TBC;
            Parms[6].Value = tPackConfig.BTBC;
            Parms[7].Value = tPackConfig.OCSN1;
            Parms[8].Value = tPackConfig.OCSN2;
            Parms[9].Value = tPackConfig.OCSN3;
            Parms[10].Value = tPackConfig.ALDSN;
            Parms[11].Value = tPackConfig.PCodeRule;
        }
        #endregion  

        
    }
}
